package com.wf.it.hpdoctor.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.wf.it.common.api.DoctorService;
import com.wf.it.common.entity.Doctor;
import com.wf.it.common.vo.Result;
import com.wf.it.hpdoctor.dao.DoctorDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorDao dao;
    @Override
    public Result findByEmpNos(String[] empNos) {
        List<Doctor> list=dao.findByEmpNoIn(empNos);
        Map<String,Doctor> map=new HashMap<>();
        for(Doctor doc:list)
            map.put(doc.getEmpNo(),doc);
        return new Result(map);
    }

    @Override
    public Result findByEmpNo(String empNo) {
        Doctor doc=dao.findByEmpNo(empNo);
        return new Result(doc);
    }

    @Override
    public Result findAll() {
        List<Doctor> list=dao.findAll();
        return new Result(list);
    }

    /*@Override
    public Result2<List<Doctor>> findAll2() {
        List<Doctor> list=dao.findAll();
        return new Result2<List<Doctor>>(list);
    }*/

    @Override
    public Result findByDept(String deptName) {
        List<Doctor> list=dao.findByDeptName(deptName);
        return new Result(list);
    }

    @Override
    public Result findById(int docid) {
        Doctor doc= dao.findById(docid).get();
        return new Result(doc);
    }

    @Override
    @LcnTransaction
    @Transactional
    public Result add(Doctor doc) {
        dao.save(doc);
        return new Result(doc);
    }
}
